#include "MyQueue.h"
#include <string.h>


int InsQueue(QUEUE_STU *arg, AudioRecvItemSt value)
{
    if(arg->count == arg->maxSize)
    {
        printf("queue is full\n");
        return -1;
    }
     
    
    memcpy(&arg->array[arg->rear], &value, sizeof(AudioRecvItemSt));
    arg->count++;
    arg->rear = (arg->rear+1) % arg->maxSize;
	
    printf("+++++++++++++++++++++++ InsQueue arg->count = %d\n", arg->count);
	return 0;
}

int PopQueue(QUEUE_STU *arg, AudioRecvItemSt *value)
{
    if(arg->count==0)
        return -1;
    memcpy(value, &arg->array[arg->front], sizeof(AudioRecvItemSt));
    arg->count--;
    arg->front = (arg->front+1) % arg->maxSize;

    printf("------------------------------ PopQueue arg->count = %d\n", arg->count);
	
	return 0;
}

int InitQueue(QUEUE_STU *arg)
{
    arg->maxSize = sizeof(arg->array)/sizeof(arg->array[0]);
    //if(arg->maxSize<1);		// always true
    //    return -1;
    arg->count = 0;
    arg->front = 0;
    arg->rear = arg->front+1;
		
	return 0;
}

int DestroyQueue(QUEUE_STU *arg)
{
    arg->rear = arg->front = 0;
    arg->count = 0;
		
	return 0;
}

// 判断队列是否为空
bool IsQueueEmpty(QUEUE_STU *queue) 
{
    if (queue == NULL) {
        return true;  // 无效参数，默认返回空
    }
    return (queue->count == 0);
}
